package com.chanyachting.emall.action.member;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Member;
import com.chanyachting.emall.exception.BuisnessException;
import com.chanyachting.emall.form.MemberForm;
import com.chanyachting.emall.service.MemberService;
import com.chanyachting.emall.serviceImpl.MemberServiceImpl;

public class RegistAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		
		MemberForm mform=(MemberForm)form;
		
		Member member=new Member();
		
		MemberService memberService=new MemberServiceImpl();
		
		try {
			
			boolean temp=memberService.regist(member);
			
			//如果注册成功，保存会员信息到session
			if(temp){
				
				request.getSession().setAttribute(MemberService.MEMBER_IN_SESSION,member);
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			
			request.setAttribute(BuisnessException.MSG_IN_REQUEST, e.getMessage());
		}
		
		
		return mapping.findForward("registSuccess");
	}
	
	
	

}
